package cn.itrip.auth.service;

import com.cloopen.rest.sdk.CCPRestSmsSDK;
import org.springframework.stereotype.Service;

import java.util.HashMap;

@Service
public class SmsServiceImpl implements SmsService {
    @Override
    public void send(String to, String templateId, String[] datas) throws Exception {
        CCPRestSmsSDK sdk = new CCPRestSmsSDK();

        //初始化一个sdk
        sdk.init("app.cloopen.com","8883");
        sdk.setAccount("8aaf07086812057f0168211ad9b706d6","f9c6f18c28fb49c0935310712e632f5e");
        sdk.setAppId("8aaf07086812057f0168211ada0e06dd");
        HashMap result= sdk.sendTemplateSMS(to,templateId,datas);
        if ("000000".equals(result.get("statusCode"))){
            System.out.println("短信发送成功");
        }else{
            throw new Exception(result.get("statusCode").toString()+":"+result.get("statusMsg").toString());
        }
    }
}
